package com.mriassl.rabbitmq.topic;

import java.io.IOException;

import com.mriassl.rabbitmq.base.AbstractConsumer;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class ReceiveLogsTopic1 extends AbstractConsumer {

	@Override
	protected void handle() throws Exception {
		channel.exchangeDeclare(TopicConsts.EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
		String queuename = channel.queueDeclare().getQueue();
		channel.queueBind(queuename, TopicConsts.EXCHANGE_NAME, "*.orange.*");

		System.out.println(" ReceiveLogsTopic1 Waiting for messages. To exit press CTRL+C");

		Consumer consumer = new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
					byte[] body) throws IOException {
				String message = new String(body, "UTF-8");
				System.out.println(" ReceiveLogsTopic1 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
			}
		};
		channel.basicConsume(queuename, true, consumer);
	}

}
